package jdbc;

import jdbc.common.InputUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class JDBCDemo10 {
    public static void main(String[] args) {
        System.out.println("欢迎注册");
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo());

        try(Connection connection = DBUtil.getConnection();
            Statement statement = connection.createStatement()){
            String sql = "insert into userinfo (username,password,nickname,age) values (?,?,?,?)";

            PreparedStatement pr = connection.prepareStatement(sql);
            pr.setString(1,userInfo.getUsername());
            pr.setString(2,userInfo.getPassword());
            pr.setString(3,userInfo.getNickname());
            pr.setInt(4,userInfo.getAge());
            int num = pr.executeUpdate();
            System.out.println(num > 0 ? "注册成功！" : "注册失败！");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
